import React from 'react';
// import areaData from '@/components/CityPicker/area.js';
// eslint-disable-next-line import/extensions
import areaData from '@/components/CityPicker/area.js';

const filterTree = tree =>
    tree.map(({ children, nameZh, id, ...props }) => ({
        children: children && children.length > 0 ? filterTree(children) : [],
        label: nameZh,
        value: nameZh,
        ...props
    }));

const useAreaData = () => {
    const [data, setData] = React.useState([]);

    React.useEffect(() => {
        // 转换成组件能识别的数据格式
        const formattedData = filterTree(areaData).sort((a, b) => a.sort - b.sort);
        setData(formattedData);
    }, []);

    return data;
};

export default useAreaData;
